package com.yykj.base.server.controller;

import com.yykj.base.client.dto.AreaDTO;
import com.yykj.base.client.dto.BaseOfficerDTO;
import com.yykj.base.client.dto.HospitalTypeListDTO;
import com.yykj.base.server.constants.HospitalLevelConstants;
import com.yykj.base.server.converter.AreaDTOConverter;
import com.yykj.base.server.dto.AppInfoDTO;
import com.yykj.base.server.model.entity.Area;
import com.yykj.base.server.service.AppInfoService;
import com.yykj.base.server.service.BaseService;
import com.yykj.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@Api(tags = "基本数据")
@RequestMapping("/api/base")
@SuppressWarnings("unchecked")
public class BaseController {

    @ApiOperation("医院类型")
    @GetMapping("/hospital/type")
    public ResultVO<HospitalTypeListDTO> getHospitalType(){
        return ResultVO.success(baseService.getHospitalType());
    }

    @ApiOperation("医院级别")
    @GetMapping("/hospital/level")
    public ResultVO<List<String>> getHospitalLevel(){
        List<String> collect = Arrays.stream(HospitalLevelConstants.values()).map(HospitalLevelConstants::getInfo).collect(Collectors.toList());
        return ResultVO.success(collect);
    }

    @ApiOperation("职称列表")
    @GetMapping("/doctor/officer")
    public ResultVO<List<BaseOfficerDTO>> getDoctorOfficer(){
        return ResultVO.success(baseService.getBaseOfficer());
    }

    @ApiOperation("地区列表")
    @GetMapping("/area/list")
    public ResultVO<List<AreaDTO>> listAllArea(@RequestParam(name = "parentCode",required = false) String parentCode){
        return ResultVO.success(AreaDTOConverter.convert(baseService.listAllArea(parentCode)));
    }

    @ApiOperation("获取App 状态信息")
    @GetMapping("/check/status")
    public ResultVO<AppInfoDTO> checkStatus(){
        return ResultVO.success(appInfoService.getAppInfo());
    }

    private BaseService baseService;

    private AppInfoService appInfoService;

    @Autowired
    public void setHospitalTypeService(BaseService baseService) {
        this.baseService = baseService;
    }

    @Autowired
    public void setAppInfoService(AppInfoService appInfoService) {
        this.appInfoService = appInfoService;
    }
}
